package com.envper.common.service.cls.impl;

import com.envper.common.domain.dto.DeviceDto;
import com.envper.common.service.cls.ClassDeviceService;
import com.envper.common.service.cls.ClassService;
import com.envper.common.service.device.DeviceService;
import com.envper.mysql.base.service.ClassDeviceBaseService;
import com.envper.mysql.domain.entity.TClassDevice;
import com.mybatisflex.core.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
@RequiredArgsConstructor
public class ClassDeviceServiceImpl implements ClassDeviceService {
    private final ClassDeviceBaseService classDeviceBaseService;
    private final ClassService classService;
    private final DeviceService deviceService;

    @Override
    public List<DeviceDto> getDeviceListByClassId(Long classId) {
        List<TClassDevice> tClassDeviceList = classDeviceBaseService.list(new QueryWrapper().eq("class_id", classId));
        if (CollectionUtils.isEmpty(tClassDeviceList)) return List.of();
        List<Long> deviceIdList = tClassDeviceList.stream().map(TClassDevice::getDeviceId).toList();
        return deviceService.getDeviceInfoListByDeviceIdList(deviceIdList);
    }
}
